package cn.tedu.store.product.webapi.controller;

import cn.tedu.store.commons.pojo.product.dto.BrandCategoryAddNewDTO;
import cn.tedu.store.product.service.IBrandCategoryService;
import cn.tedu.store.commons.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 品牌与分类关系控制器
 *
 * @author RelentlessFlow
 * @version 0.0.1
 */
@Slf4j
@Api(tags = "06.品牌与分类关系管理")
@RestController
@RequestMapping("/brand-category")
public class BrandCategoryController {
    @Autowired
    private IBrandCategoryService brandCategoryService;

    @ApiOperation("绑定品牌与类别的关联")
    @ApiOperationSupport(order = 100)
    @PostMapping("/bind")
    public JsonResult<Void> bind(BrandCategoryAddNewDTO brandCategoryAddNewDTO) {
        log.debug("开始处理【绑定品牌与类别的关联】的请求，品牌：{}，类别：{}",
                brandCategoryAddNewDTO.getBrandId(),
                brandCategoryAddNewDTO.getCategoryId());
        brandCategoryService.bind(brandCategoryAddNewDTO.getBrandId(),
                brandCategoryAddNewDTO.getCategoryId());
        return JsonResult.ok();
    }

    @ApiOperation("解绑品牌与类别的关联")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "品牌与类别关联的数据id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/unbind")
    public JsonResult<Void> unbind(@PathVariable Long id) {
        log.debug("开始处理【解绑品牌与类别的关联】的请求：id={}", id);
        brandCategoryService.unbind(id);
        return JsonResult.ok();
    }
}
